package com.example.guessthesoundtrack;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.MotionEvent;

public class Help extends Sprite {
	private Dialog dialog;

	public Help(Dialog dialog, Bitmap clicked, Bitmap unclicked, float x, float y, float width, float height) {
		super(clicked, unclicked, new Rect((int)x, (int)y, (int)(x + width), (int)(y + height)), x, y, width, height);
		this.dialog = dialog;
	}

	@Override
	public void draw(Canvas canvas) {
		canvas.drawBitmap((isDown() ? getClicked() : getUnclicked()), null, getRect(), null);
	}

	@Override
	public void update(int delta) { }

	@Override
	public void onClick(MotionEvent event, float x, float y) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			setDown(true);
			break;
		case MotionEvent.ACTION_MOVE:
			setDown(isColliding(x, y));
			break;
		case MotionEvent.ACTION_UP:
			setDown(false);
			if (!dialog.isVisible() && isColliding(x, y))
				dialog.show();
			break;
		}
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isColliding(float x, float y) {
		return (x >= getX() && y >= getY() & x <= getX() + getWidth() && y <= getY() + getHeight());
	}
}